package crp.services.api.graphql.models;


import crp.core.course.domain.models.CourseEntity;
import crp.core.timetable.domain.models.TimetableEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import org.eclipse.microprofile.graphql.Id;
import org.eclipse.microprofile.graphql.Ignore;
import org.eclipse.microprofile.graphql.Type;

import javax.validation.constraints.NotNull;
import java.time.format.TextStyle;
import java.util.List;
import java.util.Locale;

@Type("Timetable")
@Builder
@Getter
@AllArgsConstructor
public class TimetablePayload {
    @Id
    @NotNull
    private String id;
    @Ignore
    private CourseEntity course;
    @Ignore
    private List<String> facultyIds;
    @NotNull
    private Integer week;
    @NotNull
    private String dayOfWeek;
    private Integer startSlot;
    private Integer endSlot;

    public static TimetablePayload of(TimetableEntity entity) {
        return TimetablePayload.builder()
                .id(entity.getId())
                .course(entity.getCourse())
                .facultyIds(entity.getFacultyIds())
                .week(entity.getWeek())
                .dayOfWeek(entity.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.CHINESE))
                .startSlot(entity.getStartSlot())
                .endSlot(entity.getEndSlot())
                .build();
    }

}